package com.newx.limit.condition;

import com.newx.limit.constant.ConfigConstant;
import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * @author yxl
 * @date 2024/7/5 0005 18:09
 */
public class LimitAspectCondition implements Condition {

    @Override
    public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
        //检查配置文件是否包含newx.file属性
        boolean result = conditionContext.getEnvironment().containsProperty(ConfigConstant.LIMIT_TYPE);
        String property = conditionContext.getEnvironment().getProperty(ConfigConstant.LIMIT_TYPE);
        return result && (property.equals("guava") || property.equals("redis"));
    }
}
